/**
 * jquery.area.js
 * 移动端省市区三级联动选择插件
 * author: 锐不可挡
 * date: 2016-06-17
**/
/*定义三级省市区数据*/
var province = 	["北京", "天津", "河北", "河南", "山西", "山东", "内蒙古", "辽宁", "吉林", "黑龙江", "上海", "江苏", "浙江", "福建", "江西", "安徽", "湖北", "湖南", "广东", "广西", "海南", "重庆", "四川", "贵州", "云南", "西藏", "陕西", "甘肃", "青海", "宁夏", "新疆", "兵团", "其他"];
var expressArea, areaCont, areaList = $("#areaList"), areaTop = areaList.offset().top;

var provi=['我是中共党员','我不是中共党员'];
/*初始化省份*/
function intProvince() {
	areaCont = "";
	for (var i=0; i<province.length; i++) {
		areaCont += '<li onClick="selectP(' + i + ');">' + province[i] + '</li>';
	}
	areaList.html(areaCont);
	$("#areaBox").scrollTop(0);
	$("#backUp").removeAttr("onClick").hide();
}
intProvince();
/*选择省份*/
function selectP(p) {
	areaCont = "";
	areaList.html("");
	areaList.html(areaCont);
	$("#areaBox").scrollTop(0);
	expressArea = province[p];
	$("#backUp").attr("onClick", "intProvince();").show();
	clockArea();
	$("#in1").val(expressArea);
}
/*关闭省市区选项*/
function clockArea() {
	$("#areaMask").fadeOut();
	// 0607
	var deviceWidth = document.documentElement.clientWidth;
	if(deviceWidth>750){
		$("#areaLayer").animate({"top": "180%"});
	}else{
		$("#areaLayer").animate({"bottom": "-180%"});
	}
	intProvince();
}
$(function() {
	/*打开省市区选项*/
	$("#expressArea").click(function() {
		$("#areaMask").fadeIn();
		// 0607
	var deviceWidth = document.documentElement.clientWidth;
	if(deviceWidth>750){
		$("#areaLayer").animate({"top": '0'});
	}else{
		$("#areaLayer").animate({"bottom": '0'});
	}
	});
	/*关闭省市区选项*/
	$("#areaMask, #closeArea").click(function() {
		clockArea();
	});
});


/*初始化省份*/
var areaCont1
function intProvince1() {
	areaCont1 = "";
	for (var i=0; i<provi.length; i++) {
		areaCont1 += '<li onClick="selectP1(' + i + ');">' + provi[i] + '</li>';
	}
	console.log(areaCont1);
	$('#areaList1').html(areaCont1);
	$("#areaBox1").scrollTop(0);
	$("#backUp").removeAttr("onClick").hide();
}
intProvince1();
/*选择省份*/
function selectP1(p) {
	areaCont1 = "";
	$('#areaList1').html("");
	$('#areaList1').html(areaCont1);
	$("#areaBox1").scrollTop(0);
	var expressArea = provi[p];
	$("#backUp").attr("onClick", "intProvince1();").show();
	clockArea1();
	$("#in2").val(expressArea);
}
/*关闭省市区选项*/
function clockArea1() {
	$("#areaMask").fadeOut();
	$("#areaLayer1").animate({"bottom": "-100%"});
	intProvince1();
}
$(function() {
	/*打开省市区选项*/
	$("#expressArea1").click(function() {
		$("#areaMask").fadeIn();
		$("#areaLayer1").animate({"bottom": 0});
	});
	/*关闭省市区选项*/
	$("#areaMask, #closeArea1").click(function() {
		clockArea1();
	});
});